package leetcode;

public class LeetCode19 {

    //增加虚拟节点
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummy = new ListNode(0);
        dummy.next = head;
        ListNode pre = dummy, p = dummy;
        while (n >= 0) {
            p = p.next;
            n--;
        }
        while (p != null) {
            pre = pre.next;
            p = p.next;
        }
        pre.next = pre.next.next;
        return dummy.next;
    }
//------------------------------------------------------------------
}
